package demo07;
import java.util.Arrays;
public class Test07 {

    //比较接口
    //任何一个自定义类型都应该是可比较的
    public static void main(String[] args) {
        int[] arr = {4,3,6,2,1,9};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        Student[] student = new Student[3];
        student[0] = new Student("Kangkang",18,77);
        student[1] = new Student("Lisa",20,93);
        student[2] = new Student("Marya",21,89);

//        AgeComparator ageComparator = new AgeComparator();
        //排序
        ScoreComparator scoreComparator = new ScoreComparator();
        AgeComparator ageComparator = new AgeComparator();
        //按照构造器给定的方案进行排序,自己写比较器完成
        Arrays.sort(student,scoreComparator);
        System.out.println(Arrays.toString(student));
        Arrays.sort(student,ageComparator);
        System.out.println(Arrays.toString(student));


    }


    public static void bubbleSort(Comparable[] comparable){
        for (int i = 0; i < comparable.length-1; i++) {
            for (int j = 0; j < comparable.length-1-i; j++) {
                if (comparable[j].compareTo(comparable[i+1])>0){
                    Comparable temp = comparable[j];
                    comparable[j] =comparable[j+1];
                    comparable[j+1] = temp;
                }
            }

        }
    }
    public static void main2(String[] args) {
        Student[] student = new Student[3];
        student[0] = new Student("Kangkang",18,77);
        student[1] = new Student("Lisa",20,89);
        student[2] = new Student("Marya",21,93);
        bubbleSort(student);
        System.out.println(Arrays.toString(student));
    }




}
